package Test;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
 * @Auther: lizhipeng
 * @Date: 2024-10-08 - 10 - 08 - 11:00
 * @Description: Test
 * @version: 1.0
 */
public class TestLinkedHashMap {
    public static void main(String[] args) {
        //一个有序的map集合，顺序为添加顺序
        LinkedHashMap<Integer,String> linkedHashMap = new LinkedHashMap<>();
        linkedHashMap.put(4,"d");
        linkedHashMap.put(5,"e");
        linkedHashMap.put(6,"f");
        linkedHashMap.put(1,"a");
        linkedHashMap.put(2,"b");
        linkedHashMap.put(3,"c");

        //Map遍历使用Set<Map.Entry<Integer,String>>
        Set<Map.Entry<Integer,String>> entries =  linkedHashMap.entrySet();
        for(Map.Entry<Integer,String> entry: entries){
            System.out.println(entry);
        }
    }
}
